﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Lavanderia.ascx.cs" Inherits="CustomControls_Lavanderia" %>
   <script type="text/javascript">
       $(document).ready(function () {
           $("#<%= txtDocumentId.ClientID %>").autocomplete({
               source: function (request, response) {
                   $.ajax({
                       url: "<%= this.ResolveUrl("~") %>Autocomplete.asmx/FetchClientListByDocument",
                       data: "{ 'document': '" + request.term + "' }",
                       dataType: "json",
                       type: "POST",
                       contentType: "application/json; charset=utf-8",
                       dataFilter: function (data) { return data; },
                       success: function (data) {
                           $("#<%= txtDocumentId.ClientID %>").removeClass('working');
                           response($.map(data.d, function (item) {
                               return {
                                   value: item.Document,
                                   Name: item.Name,
                                   Phone: item.Phone,
                                   Address: item.Address
                               }
                           }))
                       },
                       error: function (XMLHttpRequest, textStatus, errorThrown) {
                           alert(textStatus);
                       }
                   });
               },
               minLength: 2,
               search: function () { $(this).addClass('working'); },
               open: function () { $(this).removeClass('working'); },
               close: function () { $(this).removeClass('working'); },
               select: function (e, ui) {
                   $("#<%= txtName.ClientID%>").val(ui.item.Name);
                   $("#<%= txtPhone.ClientID%>").val(ui.item.Phone);
                   $("#<%= txtAddress.ClientID%>").val(ui.item.Address);
               }
           });
           $("#<%= txtName.ClientID %>").autocomplete({
               source: function (request, response) {
                   $.ajax({
                       url: "<%= this.ResolveUrl("~") %>Autocomplete.asmx/FetchClientListByName",
                       data: "{ 'name': '" + request.term + "' }",
                       dataType: "json",
                       type: "POST",
                       contentType: "application/json; charset=utf-8",
                       dataFilter: function (data) { return data; },
                       success: function (data) {
                           $("#<%= txtName.ClientID %>").removeClass('working');
                           response($.map(data.d, function (item) {
                               return {
                                   value: item.Name,
                                   Document: item.Document,
                                   Phone: item.Phone,
                                   Address: item.Address
                               }
                           }))
                       },
                       error: function (XMLHttpRequest, textStatus, errorThrown) {
                           alert(textStatus);
                       }
                   });
               },
               minLength: 2,
               search: function () { $(this).addClass('working'); },
               open: function () { $(this).removeClass('working'); },
               close: function () { $(this).removeClass('working'); },
               select: function (e, ui) {
                   $("#<%= txtDocumentId.ClientID%>").val(ui.item.Document);
                   $("#<%= txtPhone.ClientID%>").val(ui.item.Phone);
                   $("#<%= txtAddress.ClientID%>").val(ui.item.Address);
               }
           });
       });
	</script>
<div class="form">
    <div class="required-message">Los campos indicados con <span class="required-mark">*</span> son requeridos</div>
    <div class="note-header">
        Denin Vlact <br />
        <span class="rif">V-13809162-2</span>
    </div>
    <div class="line note-code">
        <asp:Literal runat="server" ID="ltrCode"></asp:Literal>
    </div>
    <div class="line">
        <div class="field-note">
            <asp:Label runat="server" CssClass="left" ID="lblDocumentId" AssociatedControlID="txtDocumentId" 
                Text="<span class='required-mark'>*</span> C&eacute;dula / RIF"></asp:Label>
            <asp:TextBox ID="txtDocumentId" CssClass="field" runat="server" Text=''  MaxLength="255" Width="100px"></asp:TextBox>
             <asp:RequiredFieldValidator ID="reqDocumentId" runat="server" Display="None" ForeColor="Red" SetFocusOnError="true"
                ControlToValidate="txtDocumentId" ErrorMessage="La C.I/RIF es requerida"></asp:RequiredFieldValidator>
        </div>
        <div class="field-note">
            <asp:Label CssClass="left" runat="server" ID="lblName" AssociatedControlID="txtName" Text="<span class='required-mark'>*</span> Nombre"></asp:Label>
            <asp:TextBox ID="txtName" CssClass="field" runat="server" Text=''  MaxLength="255"></asp:TextBox>
            <asp:RequiredFieldValidator ID="FNvalidator" runat="server" Display="None" ForeColor="Red" SetFocusOnError="true"
                ControlToValidate="txtName" ErrorMessage="El nombre es requerido"></asp:RequiredFieldValidator>
        </div>
        <div class="clear"></div>
    </div>
    <div class="line">
        <div class="field-note">
            <asp:Label runat="server" CssClass="left" ID="lblPhone" AssociatedControlID="txtPhone" Text="<span class='required-mark'>*</span> Tel&eacute;fono"></asp:Label>
            <asp:TextBox ID="txtPhone" CssClass="short-field" runat="server"   MaxLength="255" Width="100px"></asp:TextBox>
             <asp:RequiredFieldValidator ID="reqPhone" runat="server" Display="None" ForeColor="Red" SetFocusOnError="true"
                ControlToValidate="txtPhone" ErrorMessage="El tel&eacute;fono es requerido"></asp:RequiredFieldValidator>

        </div>
        <div class="field-note">
            <asp:Label runat="server" CssClass="left" ID="lblDate" AssociatedControlID="txtDate" Text="<span class='required-mark'>*</span> Fecha"></asp:Label>
            <asp:TextBox ID="txtDate" CssClass="short-field" runat="server"   MaxLength="255" Width="100px"></asp:TextBox>
             <asp:RequiredFieldValidator ID="reqDate" runat="server" Display="None" ForeColor="Red" SetFocusOnError="true"
                ControlToValidate="txtDate" ErrorMessage="La fecha es requerida"></asp:RequiredFieldValidator>
        </div>
        <div class="clear"></div>
    </div>    
    <div class="line">
        <div class="field-note-textarea">
            <asp:Label runat="server" CssClass="left" ID="lblAddress" AssociatedControlID="txtAddress" Text="Direcci&oacute;n"></asp:Label>
            <asp:TextBox ID="txtAddress" CssClass="field" TextMode="MultiLine" runat="server" Text='' Width="80%"></asp:TextBox>
        </div>
        <div class="clear"></div>
    </div>    
    <div class="line">
        <div class="field-note-textarea">
            <asp:Label runat="server" CssClass="left" ID="lblNote" AssociatedControlID="txtNote" Text="Comentarios"></asp:Label>
            <asp:TextBox ID="txtNote" CssClass="field" runat="server" TextMode="MultiLine" Width="80%"></asp:TextBox>
        </div>
        <div class="clear"></div>
    </div>   
    <div class="field-note hide">
        <asp:Label runat="server" CssClass="left" ID="Label1" AssociatedControlID="txtNote" Text="Descontar producto de inventario"></asp:Label>
        <asp:CheckBox ID="chkDecrease" CssClass="field" runat="server" ></asp:CheckBox>
        <div class="clear"></div>
    </div>     
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel runat="server" ID="updGrid" >
        <ContentTemplate>
            <asp:gridview ID="grid" runat="server" AutoGenerateColumns="False" 
                OnRowDataBound="grid_RowDataBound" CssClass="detail-table" OnRowCreated="grid_RowCreated" ShowFooter="true" >
            <Columns>  
                <asp:TemplateField HeaderText="Proceso" HeaderStyle-CssClass="top">
                    <ItemTemplate>   
                        <asp:HiddenField runat="server" ID="hdnId" /> 
                        <asp:DropDownList runat="server" ID="drdProcess" Enabled="<%# getEnabled()%>" CssClass="detail-input"></asp:DropDownList>     
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Cantidad" HeaderStyle-CssClass="top" HeaderStyle-Width="100px">
                    <ItemTemplate>    
                        <asp:TextBox ID="txtQuantity" ReadOnly="<%# !getEnabled()%>" runat="server" CssClass="detail-input int-only quantity"></asp:TextBox>     
                    </ItemTemplate>
                </asp:TemplateField>
                    <asp:TemplateField HeaderText="P. Unitario" HeaderStyle-CssClass="top" HeaderStyle-Width="100px">
                    <ItemTemplate>    
                        <asp:TextBox ID="txtPrice" ReadOnly="<%# !getEnabled()%>" runat="server" CssClass="detail-input digits-only price"></asp:TextBox> 
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Total" HeaderStyle-CssClass="top" HeaderStyle-Width="100px">
                    <ItemTemplate>    
                        <asp:TextBox ID="txtTotal" runat="server" ReadOnly="true" CssClass="detail-input total"></asp:TextBox> 
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:gridview>
            <asp:ImageButton runat="server" ID="imgAdd" ImageUrl="~/img/plus-icon.png" CssClass="add-rows" CausesValidation="false" ToolTip="Agregar Detalles" OnClick="imgAdd_Click"/>
        </ContentTemplate>
    </asp:UpdatePanel> 
    <div class="clear"></div>
    <div class="spacer"></div>    
    <div class="buttons-actions">
        <asp:Button  runat="server" ID="btnSave" OnClick="btnSave_Click" Text="Guardar" />
        <asp:Button  runat="server" ID="btnPrint" OnClientClick="window.print()" Text="Imprimir" />
        <asp:Button runat="server" ID="btnCancel" OnClick="btnCancel_Click" CausesValidation="false" Text="Cancelar" />
    </div>
    <div class="clear"></div>
    <div class="spacer"></div>    
    <div class="validation-messages">
        <asp:ValidationSummary runat="server" ID="vSummary" />
        <asp:Label runat="server" ID="lblMessage"></asp:Label>
    </div>
    <div class="signature">
        <br /><br /><br />
        ________________________<br />
        Firma
    </div>
   <script type="text/javascript">
       $(document).ready(function () {
           if('<%= getEnabled()%>' == 'True')
           {
               $("#<%= txtDate.ClientID%>").datepicker({
                   dateFormat: 'dd/mm/yy',
               });
           }
            checkInputs();
            calculatePerRow();
            calculateTotalPerRow();
            calculateTotal();
            Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandler);
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
        })
        function checkInputs() {
            $(".digits-only").live("keyup paste", function () {
                setTimeout(jQuery.proxy(function () {
                    $(this).val($(this).val().replace(/[^\d\,]/g, ''));
                }, $(this)), 0);

            });
            $(".int-only").live("keyup paste", function () {
                setTimeout(jQuery.proxy(function () {
                    $(this).val($(this).val().replace(/[^\d]/g, ''));
                }, $(this)), 0);

            });
        }
        
        function calculatePerRow() {
            $(".digits-only, .int-only").live("blur", function () {
                var td = $(this).parent().parent();
                var qyt = td.find(".quantity");
                var price = td.find(".price");
                var total = td.find(".total");
                q = 0
                if (qyt.val() != "")
                    q = parseFloat(qyt.val().replace(/\,/g, "<%=ConfigurationManager.AppSettings["ThousandSeparator"]%>"))
                p = 0;
                if (price.val() != "")
                    p = parseFloat(price.val().replace(/\,/g, "<%=ConfigurationManager.AppSettings["ThousandSeparator"]%>"))
                t = (p * q)
                t = Math.round(t * 100) / 100;
                if (t > 0) {
                    total.val(t.toString().replace(/\./g, "<%=ConfigurationManager.AppSettings["DecimalSeparator"]%>"))
                }
                else {
                    total.val("");
                }
                calculateTotal()
            });

        }
        function calculateTotalPerRow() {
            $(".digits-only, .int-only").each(function () {
                var td = $(this).parent().parent();
                var qyt = td.find(".quantity");
                var price = td.find(".price");
                var total = td.find(".total");
                q = 0
                if (qyt.val() != "")
                    q = parseFloat(qyt.val().replace(/\,/g, "<%=ConfigurationManager.AppSettings["ThousandSeparator"]%>"))
                p = 0;
                if (price.val() != "")
                    p = parseFloat(price.val().replace(/\,/g, "<%=ConfigurationManager.AppSettings["ThousandSeparator"]%>"))
                t = (p * q)
                t = Math.round(t * 100) / 100;
                if (t > 0)
                    total.val(t.toString().replace(/\./g, "<%=ConfigurationManager.AppSettings["DecimalSeparator"]%>"))
                else
                    total.val("");
            });

        }
        function calculateTotal() {
            var gT = 0
            $(".total").each(function () {
                q = 0
                if ($(this).val() != "")
                    q = parseFloat($(this).val().replace(/\,/g, "<%=ConfigurationManager.AppSettings["ThousandSeparator"]%>"))
                gT += q;
                gT = Math.round(gT * 100) / 100;
                if (gT > 0)
                    $(".footer-subtotal").val(gT.toString().replace(/\./g, "<%=ConfigurationManager.AppSettings["DecimalSeparator"]%>"))
                else
                    $(".footer-subtotal").val("");
            });
            tax = $(".footer-tax").val();
            if (tax != "")
                ta = parseFloat(tax.replace(/\,/g, "<%=ConfigurationManager.AppSettings["ThousandSeparator"]%>"))
            ttt = Math.round(((ta * gT) / 100) * 100) / 100
            totttal = Math.round((ttt + gT) * 100) / 100;
            $(".footer-total").val(totttal);
            
        }
        function beginRequestHandler() {
            $(".dialog").dialog({
                title: "Cargando...",
                modal: true,
                width: 50,
                height: 100,
                closeOnEscape: false,
                resizable: false,
                open: function () {
                    $(".ui-dialog-titlebar-close", $(this).parent()).hide(); //hides the little 'x' button
                    $(".ui-dialog-titlebar").hide();
                }
            });
        }
        function endRequestHandler() {
            $(".dialog").dialog('close');
            calculateTotalPerRow();
            calculateTotal();
        }
    </script>
    <div class="dialog" style="display:none;text-align:center"><br /><br />Cargando...</div>
</div>    